home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #3
/
Amiga Plus CD - 2002 - No. 03.iso
/
AmiSoft
/
Util
/
Misc
/
Lottery2002.lha
/
Lottery2002
/
Source
/
handelgads.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-03-10
|
4KB
|
199 lines
/* handlegads.c */
#include "includes.h"
#include "externals.h"
BOOL handlegads(struct Window *win, struct Gadget *gads[], UWORD code, UWORD gad)
{
switch(gad)
{
case GAD_START:
get_num(win, gads);
break;
case GAD_SPEAK:
putbusy(win);
if(speaknums(wednums, 0))
speaknums(satnums, 1);
clearbusy(win);
break;
case GAD_QUIT:
return(TRUE);
break;
}
return(FALSE);
}
/* Generate the random numbers, sort them & print them */
void get_num(struct Window *win, struct Gadget *gads[])
{
int numpos = 0;
int cn1, cn2, wednum, satnum, box = 0;
LONG fuel_level = 1;
BOOL flag;
putbusy(win);
for(cn1 = 0; cn1 < 6; cn1++)
{
wednums[cn1] = 0;
satnums[cn1] = 0;
}
do
{
cn2 = 40;
do
{
flag = FALSE;
for(cn1 = 0; cn1 < cn2; cn1++)
{
wednum = (rand() % 49 + 1);
srand(seed += wednum);
satnum = (rand() % 49 + 1);
printnums(win, gads, wednum, satnum, box);
SetGadgetAttrs(gads[GAD_FUEL], win, NULL,
FUELGAUGE_Level, fuel_level++,
TAG_DONE);
}
for(cn1 = 0; cn1 < 6; cn1++)
{
if((wednum == wednums[cn1]) || (satnum == satnums[cn1]))
flag = TRUE;
}
if(flag)
cn2 = 1;
}while(flag);
wednums[numpos] = wednum; satnums[numpos] = satnum;
++box;
++numpos
}while(numpos < 6);
sortnums(wednums);
sortnums(satnums);
for(cn1 = 0; cn1 < 6; cn1++)
{
printnums(win, gads, wednums[cn1], satnums[cn1], cn1);
}
clearbusy(win);
}
/* Sort numbers */
void sortnums(int nums[])
{
int a, b, cn1;
BOOL flag;
do
{
flag = FALSE;
for(cn1 = 0; cn1 < 5; cn1++)
{
a = nums[cn1];
b = nums[cn1 + 1];
if(a > b)
{
nums[cn1] = b;
nums[cn1 + 1] = a;
flag = TRUE;
}
}
}while(flag);
}
/* Print numbers in the LOTTO_Box gadgets */
void printnums(struct Window *win, struct Gadget *gads[], int wed, int sat, int gad)
{
SetGadgetAttrs(gads[gad + 1], win, NULL,
BUTTON_Integer, wed,
TAG_DONE);
SetGadgetAttrs(gads[gad + 7], win, NULL,
BUTTON_Integer, sat,
TAG_DONE);
Delay(1);
}
BOOL speaknums(int nums[], BYTE day)
{
char num0_9[] = " 123456789";
char *num10_15[] = {"ten", "e llev en", "twelve","thir", "four", "fif"};
char *days[] = {"wedensdays", "saturdays"};
char numbuf[30];
int num, count;
BOOL flag = TRUE;
if(speakMP = CreateMsgPort())
{
if(speakIO = CreateIORequest(speakMP, sizeof(struct narrator_rb)))
{
if(OpenDevice("narrator.device", 0, (struct IORequest *)speakIO, 0L))
flag = requester(g_title,
"Could not open narrator.device", g_okbutton);
else
{
sprintf(numbuf, " %s numbers are", days[day]);
speak(numbuf);
for(count = 0; count < 6; count++)
{
num = nums[count];
if(num < 10)
sprintf(numbuf, "%c", num0_9[num]);
if(num > 9 && num < 13)
strcpy(numbuf, num10_15[num - 10]);
if(num > 12 && num < 16)
sprintf(numbuf, "%s teen", num10_15[num - 10]);
if(num > 15 && num < 20)
sprintf(numbuf, "%c teen", num0_9[num - 10]);
if(num > 19 && num < 30)
sprintf(numbuf, "twenty %c", num0_9[num - 20]);
if(num > 29 && num < 40)
sprintf(numbuf, "thirty %c", num0_9[num - 30]);
if(num > 39 && num < 50)
sprintf(numbuf, "forty %c", num0_9[num - 40]);
speak(numbuf);
}
if(day)
speak("GOOD LUCK");
CloseDevice((struct IORequest *)speakIO);
}
DeleteIORequest(speakIO);
}
else
flag = requester(g_title,
"Could not create IO request", g_okbutton);
DeleteMsgPort(speakMP);
}
else
flag = requester(g_title,
"Could not create message port", g_okbutton);
return(flag);
}
void speak(char *text)
{
BYTE speak_chan[4] = {3, 5, 10, 12};
UBYTE phontext[128];
Translate(text, strlen(text), &phontext[0], 128);
speakIO->ch_masks = &speak_chan[0];
speakIO->nm_masks = sizeof(speak_chan);
speakIO->message.io_Command = CMD_WRITE;
speakIO->message.io_Data = phontext;
speakIO->message.io_Length = strlen(&phontext[0]);
DoIO((struct IORequest *)speakIO);
Delay(5);
}